//
//  YDMainViewController.swift
//  YDWeibo01
//
//  Created by suibian on 16/8/9.
//  Copyright © 2016年 iitcast. All rights reserved.
//

import UIKit

class YDMainViewController: UITabBarController {

    override func viewDidLoad() {
    
        super.viewDidLoad()
        
//        实例化tabbar
        let tabbar = YDTabbar()
//        self.tabBar  只读属性
//      设置代理
        tabbar.ydDelegate = self
        
//        通过KVC给只读属性赋值
        setValue(tabbar, forKey: "tabBar")
        
        
        
        
        addChildViewController(YDHomeViewController(), imageName: "tabbar_home", title: "首页")
        addChildViewController(YDMessageViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(YDDiscoverViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(YDProfileViewController(), imageName: "tabbar_profile", title: "我")
        
    }

    func addChildViewController(vc:UIViewController,imageName:String,title:String) {
//        设置title 可以统一设置title
        
//        vc.navigationItem.title = title
//        vc.tabBarItem.title = title
        
            vc.title = title
        // 设置选中的文字的颜色
        
    vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        vc.tabBarItem.image = UIImage(named: imageName)
//        设置图片的渲染方式
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
//        添加自控制器
        addChildViewController(UINavigationController(rootViewController: vc))
        
        
    }
}
extension YDMainViewController:YDTabbarDelegate{

    func tabbarButtonClick() {
        print("撰写按钮点击了")
        if !YDUserAccountViewModel.sharedTools.isLogin{
        return
        
        }
        let composeVc = YDComposeViewController()
        self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
    }

}







